{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [],
   "source": [
    "import sys\n",
    "import os\n",
    "searchPath=os.path.abspath('..')\n",
    "sys.path.append(searchPath)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [],
   "source": [
    "from sklearn.model_selection import train_test_split\n",
    "from sklearn.datasets import load_iris\n",
    "import numpy as np\n",
    "from utils.plot import plot_decision_regions\n",
    "from perceptron.perceptron_base import PerceptronBase\n",
    "from perceptron.perceptron_dual import PerceptronDual"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [],
   "source": [
    "iris = load_iris()\n",
    "X = iris.data[:100, [0, 2]]\n",
    "y = iris.target[:100]\n",
    "y = np.where(y == 1, 1, -1)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "numpy.ndarray"
      ]
     },
     "execution_count": 4,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "type(X)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "numpy.ndarray"
      ]
     },
     "execution_count": 8,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "type(y)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [],
   "source": [
    "def trainData(model, X , y):\n",
    "    X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.4)\n",
    "    ppn = model(eta=0.1, n_iter=10)\n",
    "    ppn.fit(X_train, y_train)\n",
    "    plot_decision_regions(ppn, X, y)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## test PerceptronBase"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEU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21FFfDfp+H7a47vpXZ5UyTFJ28zsP5rZ5ZLulvTXxTYLANBOZo/b3S+a2e9I+htJ45L+zN3/sfCWAQBaypMqkbs/LunxgttSRUOV+ukzvpt0fD/t8d30yNwvGWcEAFQYU94BIDIE7jbMbNzM/t7MHiu7LVVjZi+b2Qkz+76ZzZfdnioxs41m9oiZ/dDMnjez/1R2m6rCzG6s/TeT/LxjZr9XdrtilCvHPaI+J+l5SVeV3ZCK+iV3pxb3Ul+S9B13//VaFdaVZTeoKtz9BUkfkVaW0nhN0qOlNipS9LhbMLMPSrpL0lfKbgviYWZXSbpV0qwkufv77n6u3FZV1h5J/+zu/1J2Q2JE4G7tf0r6Q0nLZTekolzSE2Z2vDZjFsHPSjoj6c9rabavmNnashtVUXdLerjsRsSKwN3EzPZJOu3ux8tuS4XtdvePKawY+V/N7NayG1QRayR9TNJBd/+opHclsQxyk1oK6ROSvlF2W2JF4L7UbkmfMLOXFVZCvN3MHiq3SdXi7q/XXk8r5Ch3lduiynhV0qvu/lxt+xGFQI7VPi7p79z9zbIbEisCdxN3f8DdP+juUwp/zj3t7r9RcrMqw8zWmtn65L2kOyWdLLdV1eDub0h6xcxurO3aI+kHJTapqu4RaZKeUFWCTn1A0qNmJoX/fr7m7t8pt0mV8ruSvlpLB/xI0m+X3J5KMbMrJd0h6b6y2xIzZk4CQGRIlQBAZAjcABAZAjcARIbADQCRIXADQGQI3AAQGQI3AESGwA0Akfn/yEuKPnBghloAAAAASUVORK5CYII=\n",
      "text/plain": [
       "<matplotlib.figure.Figure at 0x1161948d0>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "CPU times: user 113 ms, sys: 9.36 ms, total: 123 ms\n",
      "Wall time: 128 ms\n"
     ]
    }
   ],
   "source": [
    "%%time\n",
    "trainData(PerceptronBase ,X ,y)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## test PerceptronDual"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAW4AAAD8CAYAAABXe05zAAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAALEgAACxIB0t1+/AAAADl0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uIDIuMS4yLCBodHRwOi8vbWF0cGxvdGxpYi5vcmcvNQv5yAAAHChJREFUeJzt3XGMHNV9B/Dv7+7sW+w7uJizoQ0214SzkWurEJ8tVSebBhsrEVYaRUECKZWaWDqgLSJKqyh2/uh/vfSPRInSYNfikrYyMSqkRI2h1BgUHaDU+C5BsROInWLHEILPphhs8J1zt7/+8XZuZ/dm3szO7uzOm/1+pNPezM7MvllZP7/7ze+9J6oKIiJyR0erG0BERLVh4CYicgwDNxGRYxi4iYgcw8BNROQYBm4iIscwcBMROYaBm4jIMQzcRESO6YpzkIj0AXgYwDoACuALqvqTsON7evr12msHGtJAIqJ2cObM5HlVXR7n2FiBG8C3ADytqp8VkcUAltgOvvbaAXz1qxMxL01ERPfeK7+Je2xk4BaRqwFsAfCXAKCqVwBcSdo4IiKqT5wc90cAnAPwPRH5mYg8LCJLqw8SkRERmRCRiUuXzjW8oUREZMQJ3F0APgZgj6reCuB9AF+pPkhV96nqkKoO9fTEStMQEVECcQL3GwDeUNUjpe3HYQI5ERG1QGTgVtW3ALwuImtKu7YC+GWqrSIiolBxq0oeAPBIqaLkNQCfT69JRERkEytwq+rLAIZSbgsREcXAkZNERI5h4CYicgwDNxGRYxi4iYgcw8BNROQYBm4iIscwcBMROYaBm4jIMQzcRESOYeAmInIMAzcRkWMYuImIHMPATUTkGAZuIiLHMHATETmGgZuIyDEM3EREjmHgJiJyDAM3EZFjGLiJiBzDwE1E5BgGbiIixzBwEzWQqn2bqBEYuIkaZHwcOHy4HKxVzfb4eGvbRfnDwE3UAKrAzAzw0kvl4H34sNmemWHPmxqrq9UNIMoDEWDbNvP7Sy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4ppQNeA/D5FrcnU0RkCYA7ANzb6ra4jCMniYgcw1QJEZFjGLiJiBzDwE1E5BgGbiIixzBwExE5hoGbiMgxDNxERI5h4CYicsz/A4uBJteAUG02AAAAAElFTkSuQmCC\n",
      "text/plain": [
       "<matplotlib.figure.Figure at 0x1162d80b8>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "CPU times: user 132 ms, sys: 5.06 ms, total: 137 ms\n",
      "Wall time: 135 ms\n"
     ]
    }
   ],
   "source": [
    "%%time\n",
    "trainData(PerceptronDual ,X ,y)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.6.4"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
